<?php
class Myh_Controller_Action extends Zend_Controller_Action
{
	
	/*
	 * Load Layout Template
	 * @param string $templatePath
	 * @param string $fileConfig 
	 * @param string $session 
	 * @return Zend_Layout Object
	 */
	protected function loadTemplate($templatePath, $fileConfig = 'template.ini', $session='template')
	{
		Zend_Registry::set('moduleName',$this->getRequest()->getModuleName());
		//Clear
		$this->view->headTitle()->set('');
		$this->view->headMeta()->getContainer()->exchangeArray(array());
		$this->view->headLink()->getContainer()->exchangeArray(array());
		$this->view->headScript()->getContainer()->exchangeArray(array());
		
		$config = new Zend_Config_Ini($templatePath.'/'.$fileConfig, $session);
		$config = $config->toArray();		
		$baseUrl = $this->_request->getBaseUrl();
		$templateUrl 	= $baseUrl.$config['url'];
		$cssUrl			= $templateUrl . $config['dirCss'];
		$jsUrl			= $baseUrl . $config['dirJs'];
		$imgUrl			= $templateUrl . $config['dirImg'];
		$this->view->imgUrl = $imgUrl;
		$this->view->cssUrl = $cssUrl;
		if(count($config['metaHttp'])>0){
			foreach($config['metaHttp'] as $key => $value){
				$tmp = explode('|', $value);
				$this -> view ->headMeta()->appendHttpEquiv($tmp[0], $tmp[1]);
			}
		}
		
		if(count($config['metaName'])>0){
			foreach($config['metaName'] as $key => $value){
				$tmp = explode('|', $value);
				$this -> view ->headMeta()->appendName($tmp[0], $tmp[1]);
			}
		}
		
		if(isset($config['fileCss'])){
			foreach($config['fileCss'] as $key => $value){
				$this -> view ->headLink()->appendStylesheet($cssUrl.$value, 'screen');
			}
		}
		if(isset($config['fileJs'])){
			foreach($config['fileJs'] as $key => $value){
				$this -> view ->headScript()->appendFile($jsUrl.$value, 'text/javascript');
			}
		}
		$this -> view ->headTitle($config['title']);
		
		$option = array('layoutPath'=>$templatePath,'layout'=>$config['layout']);
		Zend_Layout::startMvc($option);
	}
	
}